package com.yuchs.test.log4j;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.filter.AbstractFilter;

/**
 * plugin filter for custom debug and trace level log to one file
 * @author tzz
 *
 */
@Plugin(name = "DebugFilter", category = "Core", elementType = "filter", printObject = true)
public class DebugFilter extends AbstractFilter {

	private DebugFilter(Result _onMatch,Result _onMismatch){
		super(_onMatch,_onMismatch);
	}
	@Override
	public Result filter(LogEvent event) {
		return event.getLevel() == Level.DEBUG || event.getLevel() == Level.TRACE ? onMatch : onMismatch;
	}
	 
	@PluginFactory
	public static DebugFilter createFilter(){
		return new DebugFilter(Result.ACCEPT,Result.DENY);
	}
}
